#ifndef __USB_SERVICE_H__
#define __USB_SERVICE_H__

/* CDC endpoint address */
#define CDC_IN_EP                               0x83
#define CDC_OUT_EP                              0x04
#define CDC_INT_EP                              0x85

/* WINUSB endpoint address */
#define WINUSB_IN_EP                            0x81
#define WINUSB_OUT_EP                           0x02

#define USBD_VID                                0x5269
#define USBD_PID                                0x6367
#define USBD_MAX_POWER                          500
#define USBD_LANGID_STRING                      1033

/* config descriptor size */
#define WINUSB_INTERFACE_SIZE                   (9 + 7 + 7)
#define USB_CONFIG_SIZE                         (9 + CDC_ACM_DESCRIPTOR_LEN + WINUSB_INTERFACE_SIZE)

#define USB_MAX_MPS                             64

#define USBD_WINUSB_VENDOR_CODE                 0x20

/* WinUSB Microsoft OS 2.0 descriptor sizes */
#define WINUSB_DESCRIPTOR_SET_HEADER_SIZE       10
#define WINUSB_FUNCTION_SUBSET_HEADER_SIZE      8
#define WINUSB_FEATURE_COMPATIBLE_ID_SIZE       20

#define FUNCTION_SUBSET_LEN                     160
#define DEVICE_INTERFACE_GUIDS_FEATURE_LEN      132

#define USBD_WINUSB_DESC_SET_LEN                (WINUSB_DESCRIPTOR_SET_HEADER_SIZE + FUNCTION_SUBSET_LEN)

#define USBD_NUM_DEV_CAPABILITIES               1

#define USBD_WINUSB_DESC_LEN                    28

#define USBD_BOS_WTOTALLENGTH                   (0x05 + USBD_WINUSB_DESC_LEN)


/* USB-UART */
#define USB2UART_PACK_SIZE                      512

typedef struct
{
    uint32_t baudrate;
    uint8_t stopbit;
    uint8_t parity;
    uint8_t databit;
}uart_config_t;

typedef void (*usb2uart_cb)(uint8_t *data, uint16_t len);
typedef void (*uart_config_cb)(uart_config_t *config);

void usb_service_uart2usb(uint8_t *data, uint16_t len);

void usb_service_usb2uart_reg(usb2uart_cb cb);
void usb_service_uart_config_reg(uart_config_cb cb);

/* USB-DAP */
#define USB2DAP_PACK_COUNT                      8
#define USB2DAP_PACK_SIZE                       512

typedef void (*usb2dap_cb)(uint8_t *data, uint16_t len);

void usb_service_dap2usb(uint8_t *data, uint16_t len);

void usb_service_usb2dap_reg(usb2uart_cb cb);

#endif
